package certification.sections.session03.cap05;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ServletCap5ContextListener implements ServletContextListener {
	
	@Override
	public void contextInitialized(ServletContextEvent event) {
		System.out.println("Iniciando o contexto da app");
		System.out.println("Estou usando o metodo contextInitialized() " +
				"da interface ServletContextListener");
		
		//Obtendo o contexto da app
		ServletContext context = event.getServletContext();
		//Obten o parameto init com o nome de dog
		String nome = context.getInitParameter("nameDog");
		//Cria Dog
		Dog dog = new Dog(nome);
		context.setAttribute("dog", dog);
	}

	@Override
	public void contextDestroyed(ServletContextEvent event) {
			System.out.println("Estou usando o metodo contextDestroyed() " +
					"da interface ServletContextListener");
	}
	
	

}
